31struct ParamsSensorBase;
32struct ParamsProcessorBase;
50#include "yaml-cpp/yaml.h"
65class Problem :
public std::enable_shared_from_this<Problem>
87 std::map<std::pair<StateBlockConstPtr, StateBlockConstPtr>, Eigen::MatrixXd>
covariances_;
120 static ProblemPtr
autoSetup(
const std::string& _input_yaml_file,
121 std::vector<std::string> _primary_schema_folders = {},
123 bool _skip_yaml_validation =
false);
128 static ProblemPtr
autoSetup(YAML::Node _param_node,
129 std::vector<std::string> _primary_schema_folders = {},
131 bool _skip_yaml_validation =
false);
183 SensorBasePtr
installSensor(YAML::Node _sensor_node, std::vector<std::string> _schema_folders = {});
189 SensorBasePtr
installSensor(
const std::string& _params_yaml_filename, std::vector<std::string> _schema_folders);
196 ProcessorBasePtr
installProcessor(YAML::Node _processor_node, std::vector<std::string> _schema_folders = {});
204 const std::string& _params_yaml_filename,
205 std::vector<std::string> _schema_folders);
213 std::vector<std::string> _schema_folders);
218 SensorBaseConstPtr
findSensor(
const std::string& _sensor_name)
const;
222 SensorBasePtr
findSensor(
const std::string& _sensor_name);
227 ProcessorBaseConstPtr
findProcessor(
const std::string& _processor_name)
const;
231 ProcessorBasePtr
findProcessor(
const std::string& _processor_name);
276 const VectorComposite& _first_frame_values,
285 FrameBasePtr
emplaceFirstFrame(
const TimeStamp& _ts,
const YAML::Node& _first_frame_node);
291 const VectorComposite& _first_frame_values,
306 const VectorComposite& _frame_state,
332 FrameBasePtr
emplaceFrame(
const TimeStamp& _time_stamp,
const VectorComposite& _frame_state);
347 const Eigen::VectorXd& _frame_state);
401 void keyFrameCallback(FrameBasePtr _keyframe_ptr, ProcessorBasePtr _processor_ptr);
434 MapBaseConstPtr
getMap()
const;
446 bool saveMap(
const std::string& _filename_dot_yaml,
447 const std::string& _map_name =
"Map automatically saved by Wolf");
453 void perturb(
double amplitude = 0.01);
457 void transform(
const VectorComposite& _transformation);
478 void addCovarianceBlock(StateBlockPtr _state1, StateBlockPtr _state2,
const Eigen::MatrixXd& _cov);
488 StateBlockConstPtr _state2,
489 Eigen::MatrixXd& _cov,
491 const int _col = 0)
const;
496 bool getCovarianceBlock(std::map<StateBlockConstPtr, unsigned int> _sb_2_idx, Eigen::MatrixXd& _cov)
const;
501 bool getCovarianceBlock(StateBlockConstPtr _state, Eigen::MatrixXd& _cov,
const int _row_and_col = 0)
const;
507 Eigen::MatrixXd& _covariance)
const;
545 void consumeNotifications(std::map<StateBlockPtr, Notification>&, std::map<FactorBasePtr, Notification>&);
566 void print(
int depth = 4,
567 bool factored_by =
false,
569 bool state_blocks =
false,
570 std::ostream& stream = std::cout)
const;
574 bool check(
int verbose_level = 0)
const;
578 bool check(
bool verbose, std::ostream& stream)
const;
614 std::map<unsigned int, MotionProviderConstPtr> map_const;
637 std::map<FactorBasePtr, Notification>& _fac_notification_map)
Interface of the processors providing motion: the state at any time stamp (and odometry)....
Definition: motion_provider.h:36
Wolf problem: root of the wolf tree (hardware, trajectory and map). It manages the motion providers,...
Definition: problem.h:66
bool getStateBlockNotification(const StateBlockPtr &sb_ptr, Notification ¬if) const
Returns whether the state block has been notified, and the notification via parameter.
Definition: problem.cpp:919
bool permitKeyFrame(ProcessorBaseConstPtr _processor_ptr) const
Give the permission to a processor to create a new key Frame.
Definition: problem.cpp:854
ProcessorBaseConstPtr findProcessor(const std::string &_processor_name) const
Returns the processor with a given name (nullptr if not found)
Definition: problem.cpp:444
void addCovarianceBlock(StateBlockPtr _state1, StateBlockPtr _state2, const Eigen::MatrixXd &_cov)
Stores the cross-covariance block between two state blocks.
Definition: problem.cpp:971
bool saveMap(const std::string &_filename_dot_yaml, const std::string &_map_name="Map automatically saved by Wolf")
Saves the map to a YAML file. Returns whether it succeeded.
Definition: problem.cpp:1273
void setFirstFrameOptions(const YAML::Node &_first_frame_node)
Sets the first frame options (types, values and priors) from a YAML node.
Definition: problem.cpp:1183
VectorComposite first_frame_values_
State values of the first frame.
Definition: problem.h:81
bool isFirstFrameSpecified() const
Returns whether the first frame options have been set.
Definition: problem.h:602
bool isFirstFrameApplied() const
Returns whether the first frame options have been applied (first frame emplaced)
Definition: problem.h:607
TrajectoryBasePtr trajectory_ptr_
Trajectory branch: the frames.
Definition: problem.h:74
void setMap(MapBasePtr)
Sets the map branch.
Definition: problem.cpp:1138
SizeStd getFactorNotificationMapSize() const
Returns the size of the map of factor notification.
Definition: problem.h:630
HardwareBaseConstPtr getHardware() const
Returns the hardware branch.
Definition: problem.cpp:1153
bool isTransformed() const
Returns whether the problem has been transformed (see transform())
Definition: problem.cpp:1371
MapBaseConstPtr getMap() const
Returns the map branch.
Definition: problem.cpp:1128
std::mutex mut_transform_
Mutex of the transformation.
Definition: problem.h:96
void print(int depth=4, bool factored_by=false, bool metric=true, bool state_blocks=false, std::ostream &stream=std::cout) const
Prints the wolf tree.
Definition: problem.cpp:1278
void resetTransformed()
Resets the transformed flag.
Definition: problem.cpp:1375
void keyFrameCallback(FrameBasePtr _keyframe_ptr, ProcessorBasePtr _processor_ptr)
New keyframe callback.
Definition: problem.cpp:865
TreeManagerBaseConstPtr getTreeManager() const
Returns the tree manager.
Definition: problem.h:592
TypeComposite frame_types_
State types of the frames.
Definition: problem.h:80
bool getCovarianceBlock(StateBlockConstPtr _state1, StateBlockConstPtr _state2, Eigen::MatrixXd &_cov, const int _row=0, const int _col=0) const
Gets the cross-covariance block between two state blocks into _cov at (_row, _col)....
Definition: problem.cpp:989
LoaderPtr loader_
Loader of the plugins.
Definition: problem.h:98
FactorBasePtr notifyFactor(FactorBasePtr _factor_ptr, Notification _notif)
Notifies a new/removed factor to update the solver manager (opposite pending notifications cancel out...
Definition: problem.cpp:928
bool getLastFrameCovariance(const StateKeys &_keys, Eigen::MatrixXd &_covariance) const
Gets the covariance of some keys of the last frame. Returns whether all blocks were found.
Definition: problem.cpp:1123
std::map< StateBlockPtr, Notification > consumeStateBlockNotificationMap()
Returns the map of state block notification to be handled by the solver (the map stored in this is em...
static ProblemPtr autoSetup(const std::string &_input_yaml_file, std::vector< std::string > _primary_schema_folders={}, LoaderPtr _loader=nullptr, bool _skip_yaml_validation=false)
Creates a problem from a YAML file (see the YAML node version)
Definition: problem.cpp:80
VectorComposite transformation_
Last transformation applied to the problem.
Definition: problem.h:95
TypeComposite getFrameTypes(StateKeys _keys) const
Returns the frame state types of some keys.
Definition: problem.cpp:764
std::map< FactorBasePtr, Notification > factor_notification_map_
Pending notifications to the solver.
Definition: problem.h:89
void perturb(double amplitude=0.01)
Perturbs the non-fixed state blocks of all nodes with random noise following a uniform distribution i...
Definition: problem.cpp:1334
void setTreeManager(TreeManagerBasePtr _gm)
Sets the tree manager.
Definition: problem.cpp:796
void transform(const VectorComposite &_transformation)
Transforms all the states of sensors, frames, captures and landmarks with a transformation.
Definition: problem.cpp:1350
FrameBasePtr emplaceFrame(const TimeStamp &_time_stamp, const TypeComposite &_frame_types, const VectorComposite &_frame_state, const PriorComposite &_frame_priors={})
Emplaces a frame from time stamp, types and state (adding the types to the problem)
Definition: problem.cpp:460
StateBlockPtr notifyStateBlock(StateBlockPtr _state_ptr, Notification _notif)
Notifies a new/removed state block to update the solver manager (opposite pending notifications cance...
Definition: problem.cpp:896
FrameBaseConstPtr getLastFrame() const
Returns the last frame of the trajectory.
Definition: problem.cpp:1163
std::map< unsigned int, MotionProviderConstPtr > getMotionProviderMap() const
Returns the motion providers indexed by their order.
Definition: problem.h:612
SizeEigen getDim() const
Returns the dimension of the problem (2 or 3)
Definition: problem.cpp:759
bool getCovariance(NodeStateBlocksConstPtr _has_states_ptr, const StateKeys &_keys, Eigen::MatrixXd &_covariance) const
Gets the covariance of some keys of a node. Returns whether all blocks were found.
Definition: problem.cpp:1084
SizeEigen dim_
Dimension of the problem (2 or 3)
Definition: problem.h:79
static ProblemPtr create(SizeEigen _dim, const TypeComposite &_frame_types={}, LoaderPtr _loader=nullptr)
Creates a problem from the dimension, the frame types and the plugin loader (use this as a constructo...
Definition: problem.cpp:71
SizeStd getStateBlockNotificationMapSize() const
Returns the size of the map of state block notification.
Definition: problem.h:624
virtual ~Problem()
Destructor.
Definition: problem.cpp:192
void addFrameTypes(const TypeComposite &_types)
Adds frame state types, checking that existing keys have the same type.
Definition: problem.cpp:775
LoaderPtr getLoader()
Returns the plugin loader.
Definition: problem.h:587
void addMotionProvider(MotionProviderPtr _processor_motion_ptr)
Adds a motion provider to the motion providers (only if it is a state provider), by its order.
Definition: problem.cpp:803
std::atomic_bool transformed_
Whether the problem has been transformed (see transform())
Definition: problem.h:94
VectorComposite stateZero(TypeComposite _types) const
Returns the zero (identity) state of some state types.
Definition: problem.cpp:835
void clearCovariance()
Clears all the covariance blocks.
Definition: problem.cpp:965
std::map< FactorBasePtr, Notification > consumeFactorNotificationMap()
Returns the map of factor notification to be handled by the solver (the map stored in this is emptied...
FrameBasePtr emplaceFirstFrame(const TimeStamp &_ts, const YAML::Node &_first_frame_node)
Sets the first frame options from a YAML node and applies them.
Definition: problem.cpp:1256
VectorComposite getState(const StateKeys &_keys) const
Returns the current state of some keys, from the motion providers by order (completed with the last f...
Definition: problem.cpp:589
std::mutex mut_covariances_
Mutex of the covariances.
Definition: problem.h:92
void consumeNotifications(std::map< StateBlockPtr, Notification > &, std::map< FactorBasePtr, Notification > &)
Moves the state block and factor notifications to the given maps, to be handled by the solver (the ma...
Definition: problem.h:636
bool check(int verbose_level=0) const
Checks the consistency of the wolf tree, printing the result if verbose_level > 0.
Definition: problem.cpp:1329
VectorComposite getOdometry(const StateKeys &_keys) const
Returns the odometry of some keys, from the motion providers by order.
Definition: problem.cpp:713
std::map< StateBlockPtr, Notification > state_block_notification_map_
Pending notifications to the solver.
Definition: problem.h:90
FrameBaseConstPtr closestFrameToTimeStamp(const TimeStamp &_ts) const
Returns the frame of the trajectory closest to a time stamp.
Definition: problem.cpp:1173
VectorComposite getTransformation() const
Returns the last transformation applied to the problem.
Definition: problem.cpp:1379
TimeStamp getTimeStamp() const
Returns the most recent time stamp of the motion providers (or of the last frame if none)
Definition: problem.cpp:569
bool getFactorNotification(const FactorBasePtr &fac_ptr, Notification ¬if) const
Returns whether the factor has been notified, and the notification via parameter.
Definition: problem.cpp:956
FrameBasePtr applyFirstFrameOptions(const TimeStamp &_ts)
Emplaces the first frame at _ts with the first frame options and calls the keyframe callback (only on...
Definition: problem.cpp:1227
MapBasePtr map_ptr_
Map branch: the landmarks.
Definition: problem.h:75
ProcessorBasePtr installProcessor(YAML::Node _processor_node, std::vector< std::string > _schema_folders={})
Installs a processor (creates it and links it to the sensor named in 'sensor_name') from a YAML node,...
Definition: problem.cpp:288
std::map< std::pair< StateBlockConstPtr, StateBlockConstPtr >, Eigen::MatrixXd > covariances_
Covariance blocks, indexed by pairs of state blocks.
Definition: problem.h:87
unsigned int first_frame_status_
0: not set, 1: set, 2: applied
Definition: problem.h:83
HardwareBasePtr hardware_ptr_
Hardware branch: the sensors and their processors.
Definition: problem.h:73
TreeManagerBasePtr tree_manager_
Tree manager.
Definition: problem.h:76
std::map< unsigned int, MotionProviderPtr > motion_provider_map_
Motion providers indexed by their order.
Definition: problem.h:77
SensorBasePtr installSensor(YAML::Node _sensor_node, std::vector< std::string > _schema_folders={})
Installs a sensor (creates it and links it to the hardware) from a YAML node, loading its plugin if n...
Definition: problem.cpp:197
SensorBaseConstPtr findSensor(const std::string &_sensor_name) const
Returns the sensor with a given name (nullptr if not found)
Definition: problem.cpp:434
std::mutex mut_notifications_
Mutex of the notification maps.
Definition: problem.h:91
void emplaceStatesToFrame(FrameBasePtr _frame_ptr, const StateKeys &_frame_keys)
Emplaces the missing states to a frame, with its time stamp.
Definition: problem.cpp:528
void removeMotionProvider(MotionProviderPtr proc)
Removes a motion provider.
Definition: problem.cpp:828
PriorComposite first_frame_priors_
State priors of the first frame.
Definition: problem.h:82
TrajectoryBaseConstPtr getTrajectory() const
Returns the trajectory branch.
Definition: problem.cpp:1143
Base class of processors: they process the captures of a sensor and the keyframes created by other pr...
Definition: processor_base.h:120
Base class of motion processors: they integrate motion data into the robot state.
Definition: processor_motion.h:110
Solver manager for WOLF.
Definition: solver_manager.h:84
Composite of state vectors.
Definition: vector_composite.h:29
Definition: capture_base.h:23
std::string StateKeys
Definition: composite.h:31
std::size_t SizeStd
Other containers size type for the Wolf project.
Definition: wolf.h:66
Composite< std::string > TypeComposite
Definition: type_composite.h:26
Notification
Type of notification of state blocks and factors to the solver manager.
Definition: problem.h:57
@ ADD
Added to the problem.
Definition: problem.h:58
@ REMOVE
Removed from the problem.
Definition: problem.h:59
EIGEN_DEFAULT_DENSE_INDEX_TYPE SizeEigen
Vector and Matrices size type for the Wolf project.
Definition: wolf.h:58
std::shared_ptr< Loader > LoaderPtr
Definition: loader.h:89
Composite< Prior > PriorComposite
Definition: prior_composite.h:87